#pragma once
#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

class InetAddr{
public:
	InetAddr(const struct sockaddr_in& addr):_addr(addr){
		_ip = inet_ntoa(_addr.sin_addr);
		_port = ntohs(_addr.sin_port);
	}

	std::string Ip() const{
		return _ip;
	}

	uint16_t Port() const{
		return _port;
	}

	bool operator==(const InetAddr& addr) const {
		return addr.Ip() == _ip && addr.Port() == _port;
	}

	struct sockaddr_in GetAddr() {
		return _addr;
	}

	std::string StringAddr(){
		return "[" + _ip + ":" + std::to_string(_port) + "]";
	}

private:
	struct sockaddr_in _addr;
	std::string _ip;
	uint16_t _port;
};